from flask_sqlalchemy import SQLAlchemy, Model


class BaseModel(Model):
    # 把一行model内容直接转成dict
    def to_dict(self):
        column_name_list = [
            value[0] for value in self._sa_instance_state.attrs.items()
        ]
        return dict(
            (column_name, getattr(self, column_name, None)) for column_name in column_name_list
        )
        pass


db = SQLAlchemy(model_class=BaseModel)
